import {AfterViewInit, Directive, ElementRef} from '@angular/core';

@Directive({
  selector: '[appD1]'
})
export class D1Directive implements AfterViewInit {

  //使用ElementRef,直接拿带有appD1这个属性的元素
  constructor(private elementRef: ElementRef) {
  }

  ngAfterViewInit() {

    this.elementRef.nativeElement.style.color = 'blue';
  }

  change(color) {
    this.elementRef.nativeElement.style.color = 'red';
  }
}
